//
//  BFBaseViewController.m
//  13KModel
//
//  Created by jack on 9/09/12.
//  Copyright (c) 2012 __butterfly__. All rights reserved.
//
#import "ATMHud.h"
#import "BFBaseViewController.h"

@interface BFBaseViewController ()
- (void)initMsgBox;
- (void)initWBEngine;
@end

@implementation BFBaseViewController
@synthesize compMessageBox, wbEngine;

- (void)initMsgBox
{
    compMessageBox = [[ATMHud alloc] initWithDelegate:self];
    [self.view addSubview:compMessageBox.view];
}

- (void)initWBEngine
{
    wbEngine = [[WBEngine alloc] initWithAppKey:kWBAppKey appSecret:kWBAppSecret];
    wbEngine.delegate = self;
    [wbEngine setRootViewController:self];
    [wbEngine setRedirectURI:@"http://"];
    [wbEngine setIsUserExclusive:NO];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self initMsgBox];
    [self initWBEngine];
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"composer_bg.png"]];
}

- (void)viewDidUnload
{
    wbEngine = nil;
    wbEngine.delegate = nil;
    compMessageBox = nil;
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)startLoadAnimation
{
    [compMessageBox setActivity:YES];
    [compMessageBox setActivityStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [compMessageBox show];
}

- (void)startLoadAnimationWithText:(NSString *)message
{
    [compMessageBox setCaption:message];
    compMessageBox.accessoryPosition = ATMHudAccessoryPositionTop;
    
    [self startLoadAnimation];
}

- (void)stopLoadAnimation
{
    [compMessageBox hide];
}

- (void)showAlertMessageBox:(NSString*)message
{
    [compMessageBox setCaption:message];
    [compMessageBox setActivity:NO];
    [compMessageBox show];
}

- (void)showAlertMessageBox:(NSString*)message delay:(NSTimeInterval)time
{
    [self showAlertMessageBox:message];
    [compMessageBox hideAfter:time];
}

- (void)navigateToPrevView
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)navigateToHomeView
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

#pragma mark- ATMHudDelegate
- (void)userDidTapHud:(ATMHud *)_hud
{
    [_hud hide];
}

@end
